import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      component:  () => import('../views/index.vue'),
      children:[
        {
          path: 'article',
          name: 'article',
          component:  () => import('../views/Article.vue')
        },
        {
          path: 'users',
          component: () => import('../views/Users.vue')
        },
        {
          path: 'custrooms',
          component: () => import('../views/customerrooms.vue')
        }
      ]
    },
    {
      path:'/login',
      name:'article',
      component: () => import('../views/Login.vue'),
    },
    {
      path: '/work',
      name: 'workindex',
      component:  () => import('../views/workindex.vue'),
      children:[
        {
          path: 'workroom',
          name: 'workroom',
          component:  () => import('../views/workrooms.vue')
        },
        {
          path: 'workcust',
          name: 'workcust',
          component:  () => import('../views/workcust.vue')
        },
        {
          path: 'worker',
          name: 'worker',
          component:  () => import('../views/workers.vue')
        },
        {
          path: 'dishes',
          name: 'dishes',
          component:  () => import('../views/dishes.vue')
        },
        {
          path: 'order',
          name: 'order',
          component:  () => import('../views/order.vue')
        },
        {
          path: 'equip',
          name: 'equip',
          component:  () => import('../views/equip.vue')
        },
        {
          path: 'item',
          name: 'item',
          component:  () => import('../views/item.vue')
        }
      ]
    }
]})
// router.beforeEach((to) => {
//   // 如果要跳转的路由是登录页面，则放过。这里一定要对放过的路由单独判断，由于下面要跳转到登录页，有可能会造成无限循环的情况。
//   if (to.name === 'login') {
//       return true;
//   }
//   // 其他路由都检查是否有token，没有的就跳转到登录页面。
//   if (!sessionStorage.token) {
//       return {name: 'login'};
//   }
// })
export default router
